package com.inwk.valoepi.managers;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;
import org.openqa.selenium.support.ui.WebDriverWait;

import com.inwk.valoepi.pages.*;


public class PageManager {

	private WebDriver driver;
	private WebDriverWait wait;
	private String baseURL;
	
	public StartPage startPage;
	public LoginPage loginPage;
	public MainPage mainPage;
	public AboutPage aboutPage;
	public ShopPage shopPage;
	public AuthorizedPage authPage;
	public UserProfilePage profilePage;
	public OrderHistoryPage orderHistoryPage;
	
	
	public PageManager(AppManager am) {
	    this.driver = am.getWebDriver();
	    this.baseURL = am.getBaseUrl();
	    //this.wait = am.
	    startPage = initElements(new StartPage(this));
	    authPage = initElements(new AuthorizedPage(this));
	    loginPage = initElements(new LoginPage(this));
	    mainPage = initElements(new MainPage(this));
	    aboutPage = initElements(new AboutPage(this));
	    shopPage = initElements(new ShopPage(this));
	    profilePage = initElements(new UserProfilePage(this));
	    orderHistoryPage = initElements(new OrderHistoryPage(this));
	    
	  }
	  
	  private <T extends Page> T initElements(T page) {
	    PageFactory.initElements(new AjaxElementLocatorFactory(driver, 10), page);
	    //PageFactory.initElements(new DisplayedElementLocatorFactory(driver, 10), page);
	    return page;
	  }
	  
	  public WebDriver getWebDriver() {
	    return driver;
	  }

	public String getBaseURL() {
		return baseURL;
	}
}
